<?php
if (! defined ( 'BASEPATH' ))
    exit ( 'No direct script access allowed' );
class thumbnail_create {
    private $CI;
		
	public function __construct() {
        $this->CI = & get_instance ();
	}
	
	public function create_image_thumbnail($base_path,$width = "",$height = "",$dir = ""){
		include_once $base_path . 'libraries/phpthumb/ThumbLib.inc.php';
		
		$set_width = $this->CI->config->item($width);
		$set_height = $this->CI->config->item($height);
		
		if (!is_dir($dir . "thumbnails/")){
			mkdir($dir . "thumbnails/");
		}
		
		$handle=opendir($dir); 
		while (false!==($file = readdir($handle))) {
			if ($file != "." && $file != "..") {
				$file_info = pathinfo($file);
			
				$thumb = PhpThumbFactory::create ( $dir . $file );
				$thumb->resize ( $set_width, $set_height );
				$thumb->save ( $dir . "thumbnails/" . "thumb_" .$file_info['filename'] . '.jpg' ,'jpg'); 
			}
		}
		closedir($handle); 
	}
}